/**
 *
 *为页面提供三维操作。operation.js
 *
 *
 * */
define(["index", "htmlDom","data"], function (index, dom,data)
{
    var container = dom.container;
    var buttonA = dom.freeCamera;
    var bookMark = dom.bookMark;
    var buttonB = dom.reset;
    var buttonC = dom.cameraMark1;
    var buttonE = dom.cameraMark2;
    var buttonF = dom.cameraMark3;
    var buttonG = dom.cameraMark4;
    var buttonD = dom.cameraMark5;
    var buttonH = dom.cameraMark6;
    var buttonI = dom.cameraMark7;
    var buttonJ = dom.cameraMark8;
    var buttonK = dom.areaCoverage;
    var buttonL = dom.cameraMark10;
    var buttonM = dom.cameraMark11;
    var buttonN = dom.cameraMark12;
    var buttonO = dom.cameraMark13;
    var buttonP = dom.cameraMark14;
    var buttonQ = dom.cameraMark15;
    var buttonR = dom.cameraMark16;
    var buttonS = dom.cameraMark17;
    var buttonT = dom.cameraMark18;
    var button = dom.button;
    var tageB = dom.tageB;
    var tageC = dom.tageC;
    var input = dom.input;
    var xf = dom.xf;
    var xf56 = dom.xf56;
    var xf57 = dom.xf57;
    var xf58 = dom.xf58;
    var sx = dom.sx;
    var sx64 = dom.sx64;
    var sx62 = dom.sx62;
    var sx60 = dom.sx60;
    var but = dom.btn;
    var color = dom.color;
    var colorValue = dom.colorValue;
    var mynumber = dom.mynumber;
    var viewPicture = dom.viewPicture;                        //显示局部图片的DOM
    var toggle = false;
    var toggle1 = false;
    var toggle2 = false;
    var viewtoggle = false;
    var interact = function (){
        //视角切换
        buttonA.onclick = function(){
           index.freeCamera();
        };
        
        //视角书签
        bookMark.onclick = function(){
            index.saveMark();
        };
        
        //视角恢复
        buttonB.onclick = function ()
        {
            index.showAll();
            index.cameraMark("viewDefault", "预设视角", 0);
            index.opacityRest();
            index.removeBorder();
            index.changeMaterial();
            index.clippingView();
            index.viewPicture();
            viewPicture.style.display = "none";
            viewtoggle = false;
            //index.waterTurnOff(true);
        };
        //透明度设置
        buttonC.onclick = function ()
        {
            if (data.temporary !== null)
            {
                mynumber.style.display = "block";

            } else
            {
                alert("请双击选中场景内的模型后再执行该操作！");
            }

        };
        button.onclick = function ()
        {
            var object = data.temporary;
            var value = input.value;
            index.opacityControl(object, value);
            mynumber.style.display = "none";
        };
        //物体显示/隐藏
        buttonE.onclick = function ()
        {
            if (data.temporary !== null)
            {
                var object = data.temporary;
                index.hoverControl(object);
            } else
            {
                alert("请双击选中场景内的模型后再执行该操作！");
            }

        };
        //边框显隐
        buttonF.onclick = function ()
        {
            if (data.temporary !== null)
            {
                var object = data.temporary;
                index.lineBorder(object);
            } else
            {
                alert("请双击选中场景内的模型后再执行该操作！");
            }

        };
        // //更换背景色
        buttonG.onclick = function ()
        {
            color.style.display = "block";
        };
        but.onclick = function ()
        {
            colorValue.click();
        };
        colorValue.onchange = function ()
        {
            var colors = this.value;
            index.backgroundChange(colors);
            color.style.display = "none";
        };
        //查看剖面
        buttonD.onclick = function ()
        {
            toggle = toggle === false;
            if (toggle)
            {
                index.clippingView(toggle);
                // document.addEventListener("mousedown",index.clippingPick,false);
                // document.addEventListener("mouseup",function(event){
                //     index.clippingBack(event);
                //     document.removeEventListener("mousedown",index.clippingPick,false);
                //
                // },false)
            }else{
                index.clippingView(toggle);
        }


        };
        
        //
        //测量
        buttonH.onclick = function ()
        {
            toggle1 = toggle1 === false;
            if (toggle1)
            {
                data.measureGroup.mesureFlag = true;
                container.removeEventListener("mousedown",index.enbalePick,false);
                container.addEventListener("mousemove",index.mesure,false);
                container.addEventListener("mousedown",index.measureLine,false);
                container.addEventListener("mouseup",index.measureLine,false);

            }else {
                data.measureGroup.mesureFlag = false;
                container.removeEventListener("mouseup",index.measureLine,false);
                container.removeEventListener("mousedown",index.measureLine,false);
                container.removeEventListener("mousemove",index.mesure,false);
                container.addEventListener("mousedown", index.enbalePick, false);
                index.removeMesure();
            }

        };
        //
        //标记
        buttonI.onclick = function(){
            toggle1 = toggle1 === false;
            if (toggle1)
            {
                container.removeEventListener("mousedown",index.enbalePick,false);
                container.addEventListener("mousedown",downClick,false);
                container.addEventListener("mouseup",upClick,false);


            }else {
                container.removeEventListener("mousedown",downClick,false);
                container.removeEventListener("mouseup",upClick,false);
                container.addEventListener("mousedown", index.enbalePick, false);
            }
        };
        function downClick(event){
            var flags = index.graphic(event);
            if(flags)container.addEventListener("mousemove",moveClick,false);

        }
        function upClick(){
            index.drawDiv();
            index.Orbcontrol.enablescope();
            container.removeEventListener("mousemove",moveClick,false);
            container.removeEventListener("mouseup",upClick,false);
            container.removeEventListener("mousedown",upClick,false);
        }
        function moveClick(event){
            index.graphicMove(event);
        }

        // //显示保存标记
        tageB.onclick = function(event){
            toggle1 = false;
            container.removeEventListener("mousedown",downClick,false);
            container.removeEventListener("mouseup",upClick,false);
            container.removeEventListener("mousemove",moveClick,false);
            container.addEventListener("mousedown", index.enbalePick, false);
            index.graphicShow(event);
            index.Orbcontrol.enablescope();
        };
        tageC.onclick = function(){
            var domS = dom.domTag;
            domS.style.display = "none";
            toggle1 = false;
            container.removeEventListener("mousedown",downClick,false);
            container.removeEventListener("mouseup",upClick,false);
            container.removeEventListener("mousemove",moveClick,false);
            index.Orbcontrol.enablescope();
            index.graphicLabeCancel();
        };
        
        //查看平面图层
        buttonJ.onclick = function(){
            toggle2 = toggle2 === false;
            index.changeMaterial(toggle2);
        };

        //查看局部区域图层
        
        buttonK.onclick = function(){
            debugger;
            viewtoggle = viewtoggle === false;
            if(viewtoggle){
            
                index.viewPicture(viewtoggle);
            
            }else{
                viewPicture.style.display = "none";
            }
            
        };
        
        
        //场景内的鼠标操作
        container.addEventListener("mousedown", index.enbalePick, false);       //单击拾取
        container.addEventListener("mouseup", index.enbalePick, false);
        container.addEventListener("dblclick", index.transferCamera, false);    //双击选中

    };
    
    
    
    
    return {
        interact: interact
    }
});